package org.example;

public class Test2 {

    public int strStr(String haystack, String needle) {
        int index1 = 0, index2 = 0, retIndex = 0;
        int n1 = haystack.length(), n2 = needle.length();
        while (index1 < n1) {
            if (haystack.charAt(index1) == needle.charAt(index2)) {
                retIndex = index1;
                while (index1 < n1 && index2 < n2
                        && haystack.charAt(index1) == needle.charAt(index2)) {
                    index1++;
                    index2++;
                }
                if (index2 == n2) return retIndex;
                else {
                    index2 = 0;
                    retIndex = -1;
                }
            }else {
                index1++;
            }
        }
        return retIndex;
    }

    public static void main(String[] args) {
        Test2 test2 = new Test2();
        test2.strStr("aaaaa","bba");
        System.out.println(777);
    }
}
